package io.ioThread;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

public class Receiver implements Runnable{
    private PipedReader reader;

    public Receiver(PipedWriter writer) throws IOException {
        this.reader = new PipedReader(writer);
    }

    @Override
    public void run() {
        char c= 0;
        try {
            while (true){
                int i=reader.read();
                if(i==-1)return;
                c = (char)i;
                System.out.print(c);
                Thread.sleep(300);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(reader!=null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
